package com.lyl.springcloud.controller;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import com.sun.deploy.security.BlockedDialog;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author lylbell
 * @date 2021-06-04 13:50
 */
@RestController
public class FlowLimitController {

    @GetMapping("/testA")
    public String testA() {
        System.out.println("1s访问一次");
        return "------testA";
    }

    @GetMapping("/testB")
    public String testB() {
        return "------testB";
    }

    @GetMapping("/testHotKey")
    @SentinelResource(value = "testHotKey",blockHandler = "deal_testHotKey")
    public String testHotKey(@RequestParam(value = "b1",required = false) String b1,
                             @RequestParam(value = "b2",required = false) String b2) {
        return "------testHotKey---";
    }
    //sentinel系统默认的提示：Blocked by Sentinel (flow limiting)
    public String deal_testHotKey(String p1, String p2, BlockException exception) {
        return "----热点key兜底方法----";
    }
}
